package geos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;

public class DAOServico {

    int cod_servico;
    String ds_servico;

    public DAOServico(int cod_servico, String ds_servico) {
        this.cod_servico = cod_servico;
        this.ds_servico = ds_servico;
    }

    public int getCod_servico() {
        return cod_servico;
    }

    public void setCod_servico(int cod_servico) {
        this.cod_servico = cod_servico;
    }

    public String getDs_servico() {
        return ds_servico;
    }

    public void setDs_servico(String ds_servico) {
        this.ds_servico = ds_servico;
    }

   
    public boolean InsertServico() {
        try {
            String sql = "INSERT INTO `geos`.`servico`VALUES(null,?);";
            Connection connection;
            connection = Banco.getConnection();
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setInt(1, this.getCod_servico());
            ps.setString(2, this.getDs_servico());
                        
            boolean result = ps.execute();
            System.out.println(ps);
            return result;
        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, "Erro de SQL. Detalhes:" + e.getMessage());
            return false;
        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(null, "Conexão Nula");
            return false;
        }

    }

}
